<template>
	<view>
    <view class="formBox">
      <u-form ref="uForm" :model="form">
        <u-form-item label="客户类型" label-width="150rpx">
          <u-input v-model="form.operatorTypeStr" disabled input-align="right"/>
        </u-form-item>
        <u-form-item label="微信昵称" label-width="150rpx">
          <u-input v-model="form.wxName" input-align="right"/>
        </u-form-item>
        <u-form-item label="联系电话" label-width="150rpx">
          <u-input v-model="form.phone" input-align="right"/>
        </u-form-item>
        <u-form-item label="生日" label-width="150rpx">
          <u-input v-model="form.birthday" disabled input-align="right" placeholder="请选择时间" type="select"
                   @click="openTimeShow()"/>
        </u-form-item>
        <u-form-item label="标签" label-width="150rpx">
          <u-input v-model="form.label" input-align="right"/>
        </u-form-item>
        <u-form-item label="备注" label-width="150rpx">
          <u-input v-model="form.remark" input-align="right"/>
        </u-form-item>
      </u-form>
    </view>
    <u-picker v-model="timeShow" :params="params" mode="time" placeholder="请选择时间" @confirm="selectTime"></u-picker>

    <view class="lxdBtn" @click="edit">保存</view>
    <u-toast ref="uToast"/>
  </view>
</template>

<script>
import {customerEdit} from '@/api/index'
import {dateFormat} from '@/utils/common/dateTime';

export default {
  data() {
    return {
      form: {
        customerNo: '',
        birthday: '',
        label: '',
        remark: '',
        phone: '',
        wxName: '',
        operatorTypeStr: ''
      },
      timeShow: false,
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
        timestamp: true
      },
    };
  },
  onLoad(option) {
    var detail = JSON.parse(option.param).detail;
    for (let key in detail) {
      for (let keys in this.form) {
        if (key == keys) {
          this.form[keys] = detail[keys];
        }
      }
    }
	},
	methods: {
    openTimeShow(type) {
      this.timeShow = true;
    },
    selectTime(e) {
      this.form.birthday = dateFormat(e.timestamp, 'yyyy-MM-dd');
    },
    edit() {
      customerEdit(this.form).then(res => {
        if (res.code == 1) {
          this.$refs.uToast.show({
            title: '修改成功',
            type: 'success',
            back: true
          });
        } else {
          this.$refs.uToast.show({
            title: res.msg,
            type: 'error'
          });
        }
      });
    }
  }
};
</script>
